//This file is the auto calibration for the light intensity sensor

#include "easybutterfly.h"
#include "macro.h"

void pre_configuration(void){

	//this function establish the configuration of the LDR sensors
	intensity1 = 0;
	intensity2 = 0;
	light_intensity1 = 0;
	light_intensity2 = 0;
	led_OFF;	//turn off both leds
	
	//this 'for' sum 10 values to create an average of the light ambient
	for(int i=0; i <= 9; i++){
		WAIT_SEC(0.1)
		BRIGHTNESS(light)	//measure the light intensity
		light_intensity1 += light;
		VOLTAGE(light)	//measure the second light intensity
		light_intensity2 += light;
	}
	light_intensity1 /= 10;	//this is for obtain a average
	light_intensity2 /= 10;


	//this 'for' sum 10 values to create an average with leds ON
	for(int i=0; i <= 9; i++){
		led_ON;
		WAIT_SEC(0.1)
		BRIGHTNESS(light)
		intensity1 += light;
		VOLTAGE(light)
		intensity2 += light;
	}
	intensity1 /= 10;
	intensity2 /= 10;

	//specify a range of tolerance between meditions
	int temp = (light_intensity1 - intensity1)/2;
	MIN_intensity1 = intensity1 + temp;

	//specify a range of tolerance between meditions
	temp = (light_intensity2 - intensity2)/2;
	MIN_intensity2 = intensity2 + temp;

}